package nz.co.doherty.gwtpbreadcrumbs.client.ui.products;

import nz.co.doherty.gwtpbreadcrumbs.client.NameTokens;
import nz.co.doherty.gwtpbreadcrumbs.client.ui.common.ListItemPresenter;
import nz.co.doherty.gwtpbreadcrumbs.shared.entity.Product;

import com.google.inject.Inject;
import com.philbeaudoin.gwtp.mvp.client.EventBus;
import com.philbeaudoin.gwtp.mvp.client.proxy.PlaceManager;
import com.philbeaudoin.gwtp.mvp.client.proxy.PlaceRequest;

public class ProductListItemPresenter
		extends ListItemPresenter<Product, ProductListItemView> {

	private final PlaceManager placeManager;

	@Inject
	public ProductListItemPresenter(EventBus eventBus,
			ProductListItemView view, PlaceManager placeManager) {
		super(eventBus, view);
		this.placeManager = placeManager;
	}

	@Override
	public void init(Product product) {
		super.init(product);
		this.view.setName(product.getName());

		this.view.setToken(placeManager
				.buildRelativeHistoryToken(new PlaceRequest(
						NameTokens.productView).with("id", Long
						.toString(product.getId()))));
	}
}
